package common.display
{
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.utils.ByteArray;

    public class ActionImageData
    {
        private var _images:BitmapData;

        private var _offsetX:int;
        private var _offsetY:int;
        private var _frame:uint;
        private var _direct:uint;

        public function ActionImageData()
        {

        }

        public function get images():BitmapData
        {
            return _images;
        }

        public function set images(value:BitmapData):void
        {
            _images = value;
        }

        public function defautl():void
        {
            _offsetX = -images.width / 2;
            _offsetY = -images.height / 2;
        }

        public function get offsetY():int
        {
            return _offsetY;
        }

        public function get offsetX():int
        {
            return _offsetX;
        }

        public function get direct():uint
        {
            return _direct;
        }

        public function get frame():uint
        {
            return _frame;
        }

        public function create(bytes:ByteArray , headlen:int):ByteArray
        {
            _frame = bytes.readUnsignedByte ();
            _direct = bytes.readUnsignedByte ();
            _offsetX = -bytes.readUnsignedShort ();
            _offsetY = -bytes.readUnsignedShort ();

            var len:uint = bytes.readUnsignedInt ();
            var offset:uint = bytes.readUnsignedInt () + headlen;
            var pos:uint = bytes.position;
            var bcontend:ByteArray = new ByteArray ();

            bcontend.writeBytes (bytes , offset , len);
            bytes.position = pos;
            return bcontend;
        }

        public function destory():void
        {
            if (_images)
            {
                _images.dispose ();
                _images = null;
            }
        }
    }
}
